package net.sf.calibur.ai.bt;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import net.sf.calibur.util.Util;

public class BTNodeAdapter implements BTNode {
	protected BTNode parent;
	protected List<BTNode> children = new ArrayList<BTNode>(1);
	protected Iterator<BTNode> iterator;
	protected long currentTick = -1;
	
	protected BTNodeAdapter(BTNode parent) {
		this.parent = parent;
	}
	
	protected BTNodeAdapter() {
		this.parent = null;
	}

	@Override
	public void addChild(BTNode child) {
		children.add(child);

	}

	@Override
	public void setParent(BTNode parent) {
		this.parent = parent;

	}

	@Override
	public BTNode getParent() {
		return parent;
	}

	@Override
	public boolean perform() {
		return false;
	}

	@Override
	public int getChildrenNum() {
		return children == null ? 0 : children.size();
	}
	
	@Override
	public Iterator<BTNode> getIterator(long tick) {
		if (currentTick != tick) {
			currentTick = tick;
			iterator = children.iterator();
		}

		return iterator;
	}
}
